<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/dtree/dtree.css" media="all">
    <link rel="stylesheet" href="../../js/lay-module/dtree/font/dtreefont.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-tab">
                <ul class="layui-tab-title">
                    <li class="layui-this">常规选项</li>
                    <li>其他选项</li>

                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <form class="layui-form layuimini-form" action="">
                            <div class="layui-form-item">
                                <label class="layui-form-label required">标题</label>
                                <div class="layui-input-block">
                                    <input type="text" name="username" lay-verify="required" lay-reqtext="请输入标题" placeholder="请输入用户名" value="" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">下拉树</label>
                                <div class="layui-input-inline">
                                    <ul id="selTree1" class="dtree" data-id="0"></ul>
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <label class="layui-form-label">跳转链接</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="open" lay-skin="switch" lay-filter="switchTest" title="开关">
                                </div>
                            </div>
                            <div class="layui-form-item" id="hrefdata" style="display: none;">
                                <label class="layui-form-label">链接</label>
                                <div class="layui-input-block">
                                    <input type="text" name="username" placeholder="请输如链接" value="" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">文档属性</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="like1[write]" lay-skin="primary" title="写作" checked="">
                                    <input type="checkbox" name="like1[read]" lay-skin="primary" title="阅读">
                                    <input type="checkbox" name="like1[game]" lay-skin="primary" title="游戏" disabled="">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">普通文本域</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">图片上传</label>
                                <div class="layui-input-block">
                                    <div class="layui-upload-drag" id="test10">
                                        <i class="layui-icon">&#xe67c</i>
                                        <p>点击上传，或将文件拖拽到此处</p>
                                        <div class="layui-hide" id="uploadDemoView">
                                            <hr>
                                            <img src="" alt="上传成功后渲染" style="max-width: 196px">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">内容编辑</label>
                                <div class="layui-input-block">
                                    <div id="editor" style="margin: 50px 0 50px 0">
                                        <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>

                    </div>

                    <div class="layui-tab-item">
                        <form class="layui-form layuimini-form" action="">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label required">作者</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="username" lay-verify="required" lay-reqtext="请输入标题" placeholder="请输入用户名" value="" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label required">浏览量</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="username" lay-verify="required" lay-reqtext="请输入标题" placeholder="请输入用户名" value="" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">阅读权限</label>
                                    <div class="layui-input-inline">
                                        <select name="interest" lay-filter="aihao">
                                                <option value=""></option>
                                                <option value="0">写作</option>
                                                <option value="1" selected="">阅读</option>
                                                <option value="2">游戏</option>
                                                <option value="3">音乐</option>
                                                <option value="4">旅行</option>
                                            </select>
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label">文章模板</label>
                                    <div class="layui-input-inline">
                                        <select name="interest" lay-filter="aihao">
                                                <option value=""></option>
                                                <option value="0">写作</option>
                                                <option value="1" selected="">阅读</option>
                                                <option value="2">游戏</option>
                                                <option value="3">音乐</option>
                                                <option value="4">旅行</option>
                                            </select>
                                    </div>
                                </div>
                            </div>


                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">发布时间</label>
                                    <div class="layui-input-inline">
                                        <input type="text" class="layui-input" id="test5" placeholder="yyyy-MM-dd HH:mm:ss">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline">
                                    <button class="layui-btn" lay-submit="" lay-filter="demo2">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>



        </div>
    </div>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js" charset="utf-8"></script>
    <script type="text/javascript">
        layui.use(['form', 'layedit', 'laydate', 'tree', 'upload', 'element', 'laydate', 'wangEditor', 'dtree'], function() {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                layedit = layui.layedit,
                laydate = layui.laydate,
                tree = layui.tree,
                dtree = layui.dtree,
                element = layui.element,
                laydate = layui.laydate,
                upload = layui.upload,
                wangEditor = layui.wangEditor;

            //富文本编译器
            var editor = new wangEditor('#editor');
            editor.customConfig.uploadImgServer = "../../api/upload.json";
            editor.customConfig.uploadFileName = 'image';
            editor.customConfig.pasteFilterStyle = false;
            editor.customConfig.uploadImgMaxLength = 5;
            editor.customConfig.uploadImgHooks = {
                // 上传超时
                timeout: function(xhr, editor) {
                    layer.msg('上传超时！')
                },
                // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式，可使用该配置
                customInsert: function(insertImg, result, editor) {
                    console.log(result);
                    if (result.code == 1) {
                        var url = result.data.url;
                        url.forEach(function(e) {
                            insertImg(e);
                        })
                    } else {
                        layer.msg(result.msg);
                    }
                }
            };
            editor.customConfig.customAlert = function(info) {
                layer.msg(info);
            };
            editor.create();


            //日期时间选择器
            laydate.render({
                elem: '#test5',
                type: 'datetime'
            });
            //拖拽上传
            upload.render({
                elem: '#test10',
                url: 'https://httpbin.org/post' //改成您自己的上传接口
                    ,
                done: function(res) {
                    layer.msg('上传成功');
                    layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src', res.files.file);
                    console.log(res)
                }
            });

            dtree.renderSelect({
                elem: "#selTree1",
                width: "100%", // 指定树的宽度
                method: 'get',
                url: "../../api/asyncTree1.json",
            });
            // 点击节点触发回调，其中obj内包含丰富的数据，打开浏览器F12查看！
            dtree.on("node('selTree1')", function(obj) {
                layer.msg(JSON.stringify(obj.param));
                console.log(obj.param); // 点击当前节点传递的参数
                console.log(obj.dom); // 当前节点的jquery对象
                console.log(obj.childParams); // 当前节点的所有子节点参数
                console.log(obj.parentParam); // 当前节点的父节点参数
            });


            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');

            //自定义验证规则
            form.verify({
                title: function(value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                },
                pass: [
                    /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'
                ],
                content: function(value) {
                    layedit.sync(editIndex);
                }
            });

            //监听指定开关
            form.on('switch(switchTest)', function(data) {

                if (this.checked) {
                    $('#hrefdata').show()
                } else {
                    $('#hrefdata').hide()
                }


            });

            //监听提交
            form.on('submit(demo1)', function(data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });
            //监听提交
            form.on('submit(demo2)', function(data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });
        });
    </script>
</body>

</html>